package com.bibrApp.difu.actvity.certificate_mvp;

import android.content.Context;

import com.bibrApp.difu.Config;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.utils.DialogUtils;
import com.bibrApp.difu.utils.EncryptUtils;
import com.bibrApp.difu.utils.ToastUtils;

import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody;

public class CertificatePresenter extends BasePresenter<ICertificateView> {
    public CertificatePresenter(Context context, ICertificateView iView) {
        super(context, iView);
    }

    /**
     * 普通实名认证
     */
    public void ordinaryCert(String name , String num) {
        DialogUtils.showDialog(context);
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", name);
        map.put("idcard", num);
        RetrofitNet.getInstance()
                .getApi()
                .ordinaryCert(EncryptUtils.encryptNewType(map))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new BaseObserver<Object>(context) {

                    @Override
                    protected void onSuccess(Object value) {
                        if(value != null){
                            ToastUtils.ShowToast(context,String.valueOf(value));
                        }

                    }
                });

    }

    /**
     * 高级实名认证
     */
    public void highCert(List<MultipartBody.Part> bodyMap) {
        DialogUtils.showDialog(context);
        RetrofitNet.getInstance()
                .getApi()
                .highCert(bodyMap)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new BaseObserver<Object>(context) {

                    @Override
                    protected void onSuccess(Object value) {
                        if(value != null){
                            ToastUtils.ShowToast(context,String.valueOf(value));
                        }

                    }
                });

    }
}
